//------------------------------------------------------------------------------
// <copyright company="Telligent Systems">
//     Copyright (c) Telligent Systems Corporation.  All rights reserved.
// </copyright> 
//------------------------------------------------------------------------------

using System;
using CommunityServer.Controls;
using System.Text.RegularExpressions;

namespace CommunityServer.Discussions.Controls
{
	/// <summary>
	/// Summary description for QuoteValidator.
	/// </summary>
	public class QuoteValidator : System.Web.UI.WebControls.BaseValidator
	{

		protected override bool EvaluateIsValid() {
			Editor editor = FindControl(this.ControlToValidate) as CommunityServer.Controls.Editor;

			if( editor != null ) {
				MatchCollection start = Regex.Matches(editor.Text, @"\[quote((?:\s*)user=(?:\""|&quot;|&#34;).*?(?:\""|&quot;|&#34;))?\]" );
				MatchCollection end = Regex.Matches(editor.Text, @"\[\/quote(?:\s*)\]" );

				return start.Count == end.Count;
			}
			else
				return true;
		}

	}
}
